import Vue from 'vue'
import Vuex from 'vuex'
// vuex数据持久化解决方案
// 1.手动添加与监听localStorage数据变化
// 2.再vuex中引入persistedstate插件
// vuex-persistedstate 默认把数据存储localStorage
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    login:false,
    musicData:{
      coverImgUrl:"",
    },  //播放列表
    userId:'',
    userId2:'',
    history:[]
  },
  mutations: {
    things2(state,obj){
      if(state.history.indexOf(obj) == -1){
        state.history.push(obj)
      }
    },
    del(state){
      console.log(state.history,"state")
      console.log("删除")
      state.history.splice(0,state.history.length)
    },
    del1(state,index){
      console.log(state.history,"state")
      console.log("删除")
      state.history.splice(index,1)
    },
    setLogin(state){
      state.login = true;
    },
    outLogin(state){
      state.login = false;
    },
    musicDatafun(state,obj){
      state.musicData = obj;
    },
    saveUserId(state,id){
      state.userId = id;
    },
    saveUserId2(state,id2){
      state.userId2 = id2;
    },
  },
  actions: {
  },
  modules: {
  },
  plugins: [createPersistedState({
    storage:window.sessionStorage
  })]
})
